package view.img;
import java.util.Hashtable;
import java.io.*;
import java.awt.*;

public class ImageLibrary
{	private static Hashtable < String, Image > images;
	private String folder="./view/img/";
	public ImageLibrary()
	{ images = new Hashtable < String, Image >();
		MediaTracker media = new MediaTracker(null);
		File imageFolder = new File(this.folder); 
		String[] children = imageFolder.list();
		if (children != null)
		{	for (int i=0; i<children.length; i++)
			{	String imageFile = children[i];
				if(imageFile.substring(imageFile.length()-4).equalsIgnoreCase(".png"))
				{	Image image = Toolkit.getDefaultToolkit().getImage(this.folder + imageFile);
					media.addImage(image, 0);
					try { media.waitForID(0); } 
					catch (Exception e) {}
					if(image != null)
					{	ImageLibrary.images.put(imageFile.substring(0,imageFile.length()-4), image); }
				}
			}
		}
	}
	public static Image getImage( String fileName )
	{ return images.get( fileName ); }
}